<?php

namespace App\Admin\Renderable;


use App\Models\Account;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class UserAccountTable extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new Account(), function (Grid $grid) {
            $user_id = $this->payload['user_id'];
            $grid->model()->with('user')
                ->where('user_id', '=', $user_id)
                ->orderByDesc('id');
            $grid->column('id');
            $grid->column('amount', trans('account.fields.amount'))->display(function ($var) {
                return $var / 100;
            });
            $grid->column('type')->display(function ($var) {
                $arr = trans('validation.account_type');
                return $arr[$var];
            });
            /*
            $grid->column('balance', trans('account.fields.balance'))->display(function ($var) {
                return $var / 100;
            });
            */
            $grid->column('created_at');
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('type')->select(trans('validation.account_type'));

            });

            $grid->disableRowSelector();
            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->disableFilterButton();
        });
    }
}
